package com.yc.fruitmarket.controller;

import java.util.List;
import java.util.Map;

import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.yc.fruitmarket.biz.blogtypeBiz;
import com.yc.fruitmarket.biz.impl.blogtypeBizImpl;

@WebServlet("/blogtypeController/*")
public class blogtypeController extends BaseServlet {
	private blogtypeBiz bb = new blogtypeBizImpl();
	
	//上架商品
			public void up(HttpServletRequest req, HttpServletResponse resp) {
				String btid = req.getParameter("btid");
				int result = bb.up(btid);
				this.send(resp, result);
			}
			
			//下架商品
			public void down(HttpServletRequest req, HttpServletResponse resp) {
				String btid = req.getParameter("btid");
				int result = bb.down(btid);
				this.send(resp, result);
			}
			
			//添加类别
			public void add(HttpServletRequest req, HttpServletResponse resp) {
				String name = req.getParameter("name");
				int result = bb.add(name);
				this.send(resp, result);
			}
			
			//获得类别
			public void gettype(HttpServletRequest req, HttpServletResponse resp) {
				List<Map<String, String>> list = bb.gettype();
				for(Map<String,String> map: list) {
					map.put("value" ,map.get("btname"));
				}
				this.send(resp, list);
			}
			
			//修改类别信息
			public void updatetype(HttpServletRequest req, HttpServletResponse resp) {
				int btid = Integer.parseInt(req.getParameter("btid"));
				String btname = req.getParameter("btname");
				int result = bb.updatetype(btid, btname);
				this.send(resp, result);
			}
			
			//条件查询
			public void getbytype(HttpServletRequest req, HttpServletResponse resp) {
				String btname = req.getParameter("btname");
				String status = req.getParameter("status");
				List<Map<String, String>> list = bb.getbytype(btname, status);
				this.send(resp, list);
				
			}
	
	//简单查询博客类别
	public void findBlogType(HttpServletRequest req, HttpServletResponse resp) {
		List<Map<String, String>> list = bb.findBlogType();
		if(list.size() > 0) {
			this.send(resp, list);
		}else {
			return;
		}
	}
	//同时查询类别数量
	public void getBlogTypes(HttpServletRequest req, HttpServletResponse resp) {
		List<Map<String, String>> list = bb.getBlogTypes();
		if(list.size() > 0) {
			this.send(resp, list);
		}else {
			return;
		}
	}
}
